package com.lhkj.ct.quartz.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.quartz.model.entity.TblJobLog;
import com.lhkj.ct.quartz.service.SysJobLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 *      定时任务调度日志表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2023-09-23
 */
@RestController
@RequestMapping("api/system/job/log")
@Api(tags = "15.定时任务日志")
@ApiSupport(order = 15)
@Validated
public class SysJobLogController {

    @Resource
    private SysJobLogService jobLogService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "定时任务日志列表", notes = "分页查询")
//    //@RequiresPermissions("@ss.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public ActionResult<IPage<TblJobLog>> list(TblJobLog jobLog) {
        return ActionResult.success(jobLogService.selectJobPage(jobLog));
    }

    /**
     * 根据调度编号获取详细信息
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "日志详细信息")
//    //@RequiresPermissions("@ss.hasPermi('monitor:job:query')")
    @GetMapping(value = "/{jobLogId}")
    public ActionResult<TblJobLog> getInfo(@PathVariable String jobLogId) {
        return ActionResult.success(jobLogService.selectById(jobLogId));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "删除日志")
//    //@RequiresPermissions("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "任务调度日志", actionType = ActionType.DELETE)
    @DeleteMapping("/delete")
    public ActionResult<Void> remove(@NotEmpty(message = "日志id不能为空") @RequestBody List<String> ids) {
        return ActionResult.judge(jobLogService.removeByIds(ids));
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "清空日志")
//    //@RequiresPermissions("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "任务调度日志", actionType = ActionType.CLEAN)
    @DeleteMapping("/clean")
    public ActionResult<Void> clean() {
        jobLogService.clear();
        return ActionResult.success();
    }
}
